<%@ Control Language="C#" ClassName="StateFlow_Actions" Inherits="Dimok.Web.UI.TableControl" %>
<%@ Register Namespace="Dimok.Web.UI"  Assembly="Dimok.Web.UI" TagPrefix="OR"  %>
<%@ Register Namespace="Data.DataSources" Assembly="App_Code" TagPrefix="DS"  %>
<%@ Import Namespace="System.Collections.Generic" %>
<script runat="server">
	private int _stateFromID = -1;
	private int _stateToID = -1;
	private bool _shortVersion = false;
	public int StateFromID { set { ds.SetStateIDParameter(value); _stateFromID = value; } }
	public bool ShortVersion { get { return _shortVersion; } set { _shortVersion = value; } }
	public string TableName { set { ds.TableName = value; } }
	protected override void OnPreRender(EventArgs e) {
		SelectFilter = ds.Filter;
		base.OnPreRender(e);
		if( _stateFromID >= 0 )((DropDownList)grv.FooterRow.Cells[2].FindControl("StateFromID")).SelectedValue = _stateFromID+"";
		if( _stateToID >= 0 )((DropDownList)grv.FooterRow.Cells[3].FindControl("StateToID")).SelectedValue = _stateToID+"";
	}
	protected void grv_RowDataBound(object sender, GridViewRowEventArgs e) {
		if(!ShortVersion) return;
		for(int i = 0; i < 4; i++)
			e.Row.Cells[i].Visible = false;
		((GridView)sender).ShowFooter = false;
	}
</script>

<asp:UpdatePanel ID="pnlRebateOffers" UpdateMode="Always" runat="server">
	<ContentTemplate>
<OR:GridViewEx ID="grv" runat="server" AutoGenerateColumns="False" DataSourceID="ds"
	ShowFooter="True" AllowSorting="True" BackColor="Window" CellPadding="0" EnableTheming="True"
	Font-Names="verdana" EnableViewState="False" DataKeyNames="StateFromID,StateToID,StateFlowActionID"
	OnRowDataBound="grv_RowDataBound"
	>
	<Columns>

		<asp:TemplateField HeaderText="TableName" SortExpression="TableName">
			<ItemTemplate><asp:Label Text='<%#Eval("TableName") %>' runat="server" /></ItemTemplate>
			<EditItemTemplate><asp:Label Text='<%#Eval("TableName") %>' runat="server" /></EditItemTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="From" SortExpression="StateFrom">
			<ItemTemplate><asp:Label Text='<%#Eval("StateFrom") %>' runat="server" /></ItemTemplate>
			<EditItemTemplate>
				<asp:DropDownList ID="selStateFromID" DataSourceID="dsStates" DataTextField="NameLong" DataValueField="ID" runat="server"
						 SelectedValue='<%# Bind("StateFromID") %>'></asp:DropDownList>
			</EditItemTemplate>
			<FooterTemplate>
				<UI:DropDownListEx ID="StateFromID" DataSourceID="dsStates" DataTextField="NameLong" DataValueField="ID" runat="server" />
			</FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="To" SortExpression="StateTo">
			<ItemTemplate><asp:Label Text='<%#Eval("StateTo") %>' runat="server" /></ItemTemplate>
			<EditItemTemplate>
				<asp:DropDownList ID="selStateToID" DataSourceID="dsStates" DataTextField="NameLong" DataValueField="ID" runat="server"
						 SelectedValue='<%# Bind("StateToID") %>'></asp:DropDownList>
			</EditItemTemplate>
			<FooterTemplate>
				<UI:DropDownListEx ID="StateToID" DataSourceID="dsStates" DataTextField="NameLong" DataValueField="ID" runat="server" />
			</FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="Action Name" SortExpression="StateFlowActionName">
			<ItemTemplate><asp:Label Text='<%#Eval("StateFlowActionName") %>' Title='<%#Eval("StateFlowActionText") %>' runat="server" /></ItemTemplate>
			<EditItemTemplate>
				<asp:DropDownList ID="selStateFlowActionID" DataSourceID="dsStateFlowActions" DataTextField="Name" DataValueField="ID" runat="server"
						 SelectedValue='<%# Bind("StateFlowActionID") %>'></asp:DropDownList>
			</EditItemTemplate>
			<FooterTemplate>
				<asp:DropDownList ID="StateFlowActionID" DataSourceID="dsStateFlowActions" DataTextField="Name" DataValueField="ID" runat="server"></asp:DropDownList>
			</FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="Priority" SortExpression="Priority">
			<ItemTemplate><asp:Label Text='<%#Eval("Priority") %>' runat="server" /></ItemTemplate>
			<EditItemTemplate><asp:TextBox ID="txtPriority" Text='<%#Bind("Priority") %>' runat="server" /></EditItemTemplate>
			<FooterTemplate><asp:TextBox ID="Priority" runat="server" /></FooterTemplate>
		</asp:TemplateField>

	</Columns>
</OR:GridViewEx>
	</ContentTemplate>
</asp:UpdatePanel>

<DS:StateFlow_ActionsDataSource ID="ds" runat="server" />
<DS:StatesDataSource ID="dsStates" runat="server" />
<DS:StateFlowActionsDataSource ID="dsStateFlowActions" runat="server" />
